﻿using TPXSDK.NET.Link;
using TPXSDK.NET.Share;
using TPXSDK.NET.UObject;

namespace TPXSDK.NET.UAV;

/// <summary>
/// UAV工具类
/// </summary>
public static class UAVUtils
{
    /// <summary>
    /// 将飞行模式转换为字符串
    /// </summary>
    public static string FlightMode2Str(byte mode, UDevType t)
    {
        return t switch
        {
            UDevType.PLANE when 0 == mode => Tr.Get("Manual"),
            UDevType.PLANE when 1 == mode => Tr.Get("Assist"),
            UDevType.PLANE when 2 == mode => Tr.Get("Auto"),

            UDevType.COPTER when 0 == mode => Tr.Get("Stab"),
            UDevType.COPTER when 1 == mode => Tr.Get("AltHold"),
            UDevType.COPTER when 2 == mode => Tr.Get("Loiter"),
            UDevType.COPTER when 3 == mode => Tr.Get("Auto"),
            UDevType.COPTER when 4 == mode => Tr.Get("Follow"),
            UDevType.COPTER when 5 == mode => Tr.Get("Strike"),
            UDevType.COPTER when 6 == mode => Tr.Get("Offboard"),
            UDevType.COPTER when 7 == mode => Tr.Get("Eject"),
            UDevType.COPTER when 8 == mode => Tr.Get("Swarm"),

            UDevType.VTOL when 0 == mode => Tr.Get("Manual"),
            UDevType.VTOL when 1 == mode => Tr.Get("Assist"),
            UDevType.VTOL when 2 == mode => Tr.Get("QStab"),
            UDevType.VTOL when 3 == mode => Tr.Get("QLoiter"),
            UDevType.VTOL when 4 == mode => Tr.Get("AltHold"),
            UDevType.VTOL when 5 == mode => Tr.Get("Auto"),
            UDevType.VTOL when 6 == mode => Tr.Get("Offboard"),
            _ => $"FM-{mode}?"
        };
    }

    /// <summary>
    /// 根据设备类型获得自主模式编码
    /// </summary>
    public static byte AutoModeCode(UDevType t)
    {
        return t switch
        {
            UDevType.PLANE => 2,
            UDevType.COPTER => 3,
            UDevType.VTOL => 5,
            _ => 0
        };
    }

    /// <summary>
    /// 将爬升状态字转换为字符串
    /// </summary>
    public static string ClimbState2Str(byte state)
    {
        return state switch
        {
            0 => Tr.Get("ClimbState.Level"),
            1 => Tr.Get("ClimbState.Climb"),
            2 => Tr.Get("ClimbState.Descend"),
            _ => "FS?"
        };
    }

    /// <summary>
    /// 将飞行阶段转换为字符串
    /// </summary>
    public static string FlightStage2Str(FlightStage stage)
    {
        return stage switch
        {
            FlightStage.IDLE => Tr.Get("Auto.Idle"),
            FlightStage.TAKEOFF => Tr.Get("Auto.Takeoff"),
            FlightStage.WPNAV => Tr.Get("Auto.WpNav"),
            FlightStage.CIRCLE => Tr.Get("Auto.Circle"),
            FlightStage.GUIDED => Tr.Get("Auto.Guided"),
            FlightStage.RTL => Tr.Get("Auto.Rtl"),
            FlightStage.LAND => Tr.Get("Auto.Land"),
            FlightStage.TRANS => Tr.Get("Auto.Trans"),
            FlightStage.HOVER => Tr.Get("Auto.Hover"),
            _ => "Stage?"
        };
    }

    /// <summary>
    /// 获取设备类型名称
    /// </summary>
    /// <param name="UavType"></param>
    /// <returns></returns>
    public static string UDevTypeName(UDevType UavType)
    {
        if (UavType == UDevType.COPTER) return "COPTER";
        if (UavType == UDevType.PLANE) return "PLANE";
        if (UavType == UDevType.VTOL) return "VTOL";
        return "UNKNOWN";
    }
}
